package com.loongtech.bi.action.game;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.loongtech.bi.entity.game.EntityActiveUserSchool;
import com.loongtech.bi.entity.game.EntityNewUserSchool;
import com.loongtech.bi.manager.game.ActiveUserSchoolManager;
import com.loongtech.bi.manager.game.NewUserSchoolManager;
import com.loongtech.bi.manager.game.SchoolGameManager;
import com.loongtech.bi.manager.game.SchoolGameManager.SchoolGameData;
import com.loongtech.bi.manager.game.SchoolGameManager.SchoolGameSumData;
import com.loongtech.bi.manager.system.GameParamConfigManager;
import com.loongtech.bi.manager.system.SysLogManager;
import com.loongtech.bi.support.CommonGameParam;
import com.loongtech.bi.support.Session;
import com.loongtech.bi.support.chart.ChartUIData;
import com.loongtech.core.util.Time;

/**
 * 游戏内分析-职业分析Action
 * @author Marin
 * @date 2015年09月17日
 */
@Controller
@Scope("view")
public class SchoolGameAction {
	private Date dateStart = new Date(Time.getBeginningOfDay(Time.currentTime() - 8 * Time.DAY));  // 前端传过来的开始时间
	private Date dateEnd = new Date(Time.getBeginningOfDay(Time.currentTime() - Time.DAY));  // 前端传过来的结束时间
	
	private List<SchoolGameSumData> schoolGameSumData;
	private List<ChartUIData> pieChartList;  // 前端要显示的二个饼状图数据
	private List<SchoolGameData> schoolGameData;
	
	@Autowired
	SchoolGameManager schoolGameManager;
	@Autowired
	ActiveUserSchoolManager activeUserSchoolManager;
	@Autowired
	NewUserSchoolManager newUserSchoolManager;
	
	@Autowired
	private SysLogManager sysLogManager;
	@Autowired
	private Session session;
	
	@PostConstruct
	public void init() {
		search();
	}

	public void search() {
		sysLogManager.addLog(session.getUserName(), "游戏内分析-职业分析");
		
		pieChartList = new ArrayList<>();
		schoolGameSumData = new ArrayList<>();
		schoolGameData = new ArrayList<>();
		
		List<EntityActiveUserSchool> activeUserSchoolList = activeUserSchoolManager.getAllActiveUserSchool(dateStart, dateEnd);
		List<EntityNewUserSchool> newUserSchoolList = newUserSchoolManager.getAllNewUserSchool(dateStart, dateEnd);
		if ((activeUserSchoolList != null && activeUserSchoolList.size() > 0) || (newUserSchoolList != null && newUserSchoolList.size() > 0)) {
			schoolGameManager.updateSchoolData(dateStart, dateEnd, activeUserSchoolList, newUserSchoolList, schoolGameSumData, pieChartList, schoolGameData);
		} else {
			if (activeUserSchoolList == null || activeUserSchoolList.size() <= 0) {
				schoolGameSumData = null;
			}
			if (newUserSchoolList == null || newUserSchoolList.size() <= 0) {
				schoolGameData = null;
			}
		}
	}
	
	public String getSchoolNameById(int id) {
		return GameParamConfigManager.getItemsRevise(CommonGameParam.SCHOOL).get(String.valueOf(id)); //SchoolManager.getSchoolNameById(id);
	}
	
	public Date getDateStart() {
		return dateStart;
	}

	public void setDateStart(Date dateStart) {
		this.dateStart = dateStart;
	}

	public Date getDateEnd() {
		return dateEnd;
	}

	public void setDateEnd(Date dateEnd) {
		this.dateEnd = dateEnd;
	}

	public List<ChartUIData> getPieChartList() {
		return pieChartList;
	}

	public void setPieChartList(List<ChartUIData> pieChartList) {
		this.pieChartList = pieChartList;
	}

	public List<SchoolGameData> getSchoolGameData() {
		return schoolGameData;
	}

	public void setSchoolGameData(List<SchoolGameData> schoolGameData) {
		this.schoolGameData = schoolGameData;
	}

	public List<SchoolGameSumData> getSchoolGameSumData() {
		return schoolGameSumData;
	}

	public void setSchoolGameSumData(List<SchoolGameSumData> schoolGameSumData) {
		this.schoolGameSumData = schoolGameSumData;
	}
}
